#include "Core.h"

bool Core::OnInit()
{
#pragma region SDL_INIT
	if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
	{
		return false;
	}
#pragma endregion

#pragma region GRAPHICS_INIT
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, config->getAsInt("GL_RED_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, config->getAsInt("GL_GREEN_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, config->getAsInt("GL_BLUE_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, config->getAsInt("GL_ALPHA_SIZE"));

	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, config->getAsInt("GL_DEPTH_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, config->getAsInt("GL_BUFFER_SIZE"));

	SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, config->getAsInt("GL_ACCUM_RED_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, config->getAsInt("GL_ACCUM_GREEN_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, config->getAsInt("GL_ACCUM_BLUE_SIZE"));
	SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, config->getAsInt("GL_ACCUM_ALPHA_SIZE"));

	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, config->getAsInt("GL_MULTISAMPLEBUFFERS"));
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, config->getAsInt("GL_MULTISAMPLESAMPLES"));

	if((Surf_Display = SDL_SetVideoMode(
		config->getAsInt("ScreenWidth"), 
		config->getAsInt("ScreenHeight"), 
		config->getAsInt("ScreenBPP"), 
		SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)
		) == NULL)		
	{		
			return false;	
	}

	glClearColor(0, 0, 0, 0);
	glClearDepth(1.0f);

	glViewport(0, 0, 640, 480);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(0, 640, 480, 0, 1, -1);
	//gluPerspective(0, 0, 1, -1);

	glMatrixMode(GL_MODELVIEW);

	glEnable(GL_TEXTURE_2D);

	glLoadIdentity();
#pragma endregion

	SDL_ShowCursor(config->getAsInt("ShowMouse"));

	return true;
}